<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://unpkg.com/vue@next"></script>
</head>
<body>
    <div id="app">
    </div>
    <div id="height"></div>
    <div id="score"></div>
</body>
<script>
    const app = document.getElementById('app')
    const height = document.getElementById('height')
    const score = document.getElementById('score')
    function defineReactive(data, key, val) {
        Object.defineProperty(data, key, {
            enumerable: true,
            configurable: true,
            get: function () {
                console.log('get val:', val)
                return val
            },
            set:function (newVal) {
                console.log('set val:', newVal, val)
                val = newVal
                updated()
            }
        })
    }
    const obj = {
        name: 'jack',
        age: 20,
        height: 180.0
    }
    const vm = {

    }
    function observe(data) {
        Object.keys(data).forEach((key) => {
            defineReactive(vm, key, data[key])
        })
        console.log('vm:', vm)
    }
    observe(obj)

    function updated() {
        app.innerHTML = vm.name
        height.innerHTML = vm.height
        score.innerHTML = vm.score
    }

    defineReactive(vm, 'score', 0)
    setTimeout(()=>{
        vm.score = 60
        vm.name = 'andy'
        vm.height = 120.333
    },2000)
</script>
</html>
